hysop.operator.transpose module

@file transpose.py Transposition related operators.

class hysop.operator.transpose.Transpose(fields, variables, axes, output_fields=None, implementation=None, name=None, base_kwds=None, **kwds)[source]

Bases: ComputationalGraphNodeGenerator

Operator generator for inplace and out of place field transposition and permutations in general.

Available implementations are:

*python (numpy based transpose, n-dimensional) *opencl (opencl codegen based transpose up to 16D)

Implementations handle only one field at a time but this graph node generator generates an operator per supplied field, possibly on different implementation backends.

See hysop.operator.base.transpose_operator.TransposeOperatorBase for operator backend implementation interface.

Initialize a Transpose operator generator operating on CartesianTopology topologies.

Parameters:
  • fields (Field, list or tuple of Fields) – Input continuous fields to be transposed, at least 2D. All fields should have the same dimension.

  • output_fields (Field, list or tuple of Fields, optional) – Output continuous fields where the results are stored. Transposed shapes should match the input. By default output_fields are the same as input_fields resulting in inplace transpositions. Input and output are matched by order int list/tuple.

  • variables (dict) – Dictionary of fields as keys and CartesianTopologyDescriptors as values.

  • axes (tuple of ints, or array like of tuples, or dict of (tuple, TranspositionState).) –

    Permutation of axes in numpy notations (as a tuple of ints). Axe dim-1 is the contiguous axe, axe 0 has the greatest stride in memory.

    It can also be an array like of axes and the operator implementation will choose the most suitable axe permutation scheme in this list.

    If a dictionnary is provided, this gives the operator implementation to choose the most suitable axe permutation scheme with the knowledge of the target transposition state as well.

    All fields on the same backend will perform the same permutation. Operator chosen permutation can be retrieved by using generated operator ‘axes’ attribute.

  • implementation (Implementation, optional, defaults to None) –

    target implementation, should be contained in available_implementations(). If implementation is set and topology does not match backend,

    RuntimeError will be raised on _generate.

    If None, implementation will be set according to topologies backend, different implementations may be choosen for different Fields if defined on different backends.

  • name (string) – prefix for generated operator names

  • base_kwds (dict, optional, defaults to None) – Base class keywords arguments. If None, an empty dict will be passed.

  • kwds – keywords arguments that will be passed towards implementation transpose operator __init__.

Notes

Out of place transpose will always be faster to process. The only exception to this rule may be 2D square matrices.

Inplace transposition may request a temporary buffer because not all implementations may support inplace transposition.

  • Example for axes:
    • In 4D, axes=(0,1,2,3) means no permutations at all, this will raise ValueError.

    • In 2D, axes=(1,0) is a transposition.

    • In 3D, axes=(0,2,1) is a transposition in the XY-plane.

  • About dimensions:
    • No limit for the numpy CPU transposition implementation.

    • Max 16D for the OpenCL implementation.

A Transpose operator implementation should support the TransposeOperatorBase interface (see hysop.operator.base.transpose_operator.TransposeOperatorBase).

This ComputationalGraphNodeFrontend will generate a operator for each input and output ScalarField pair.

All implementations should raise TranspositionNotImplementedError is the user supplied parameters leads to unimplemented or unsupported transposition features.

classmethod default_implementation()[source]
classmethod implementations()[source]
exception hysop.operator.transpose.TranspositionNotImplementedError[source]

Bases: NotImplementedError

Error raised for unimplemented transposition operator configurations.